/**
 * Small MooTools script for creating the pastecode in the settings.
 * @author Daniel Eliasson Stilero Webdesign
 */
window.addEvent('domready', function(){
        var profileID;
        var profileTypeSelection = $('jform_params_profile_type').value;
        var profileType = 'author';
        if(profileTypeSelection == '2'){
            profileType = 'publisher';
        }
        var theme = '';
        var themeSelection = $('jform_params_theme').value;
        if (themeSelection == '2'){
            theme = ' theme="dark"';
        }
        var width = $('jform_params_width').value;
        var height = $('jform_params_height').value;
    $('jform_params_profileid').addEvent('change', function(){
        profileID = $('jform_params_profileid').value;
        updatePasteCode();
    });
    $('jform_params_profile_type').addEvent('change', function(){
        profileType = 'author';
        if($('jform_params_profile_type').value == '2'){
            profileType = 'publisher';
        }
        updatePasteCode();
    });
    $('jform_params_width').addEvent('change', function(){
        width = $('jform_params_width').value;
        if(width < 100 ){
            width = 100;
            $('jform_params_width').value = width;
        }else if(width > 1024){
            width = 1024;
            $('jform_params_width').value = width;
        }
        updatePasteCode();
    });
    $('jform_params_height').addEvent('change', function(){
        height =  $('jform_params_height').value;
        if(height < 69 ){
            height = 69;
            $('jform_params_height').value = height;
        }
        updatePasteCode();
    });
    $('jform_params_theme').addEvent('change', function(){
        theme = '';
        if($('jform_params_theme').value == '2'){
            theme = ' theme="dark"';        
        }
        updatePasteCode();
    });
    var updatePasteCode = function(){
        var pasteCode = '<g:plus href="https://plus.google.com/' + profileID + 
            '" rel="' + profileType + 
            '" width="' + width + 
            '" height="' +  height + 
            theme +
            '"></g:plus>';
        $('jform_params_pastecode').value = pasteCode;
    };
});